Plots the State Transition Graph

Plots STG for a couple of boolean networks. Note that for large networks the STG can be very large.


In [1]:
%load_ext autoreload
%autoreload 2
%matplotlib inline

In [2]:
import cana
from cana.datasets.bio import MARQUESPITA
import networkx as nx
import graphviz
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rc('font', **{'size':16})

In [3]:
N = MARQUESPITA()

In [4]:
STG = N.state_transition_graph()
#print STG.nodes(data=True)
attractors = N.attractors(mode='stg')
print('STG: %s' % (attractors))
attractors_ = N.attractors(mode='bns')
print('BNS: %s' % (attractors_))


STG: [[126]]
BNS: [[126]]

In [5]:
# Draw the State Transition Graph
G = graphviz.Digraph(name='State Transition Graph', engine='neato')
G.attr('graph', concentrate='true', simplify='true', overlap='true')
G.attr('node', shape='circle', fixedsize='true', width='.4', color='#488957', style='filled', fillcolor='#24442b', penwidth='3', fontname='Helvetica', fontcolor='white',fontsize='9')
G.attr('edge', arrowhead='normal', arrowsize='.1', color='#545454')

for node,d in STG.nodes(data=True):
    if any(node in attractor for attractor in attractors): #node in attractors:
        label = d['label']
        width = '0.6'
        penwidth = '3'
    else:
        label = ''
        width = '0.1'
        penwidth = '1'
    G.node(name=str(node), label=label, width=width, penwidth=penwidth)
for s,t,d in STG.edges(data=True):
    G.edge(str(s),str(t))
print('Nodes: %d | Edges: %d' % (len(STG.nodes()) , len(STG.edges()) ))
G


Nodes: 128 | Edges: 128
Out[5]:
State Transition Graph 0 126 1111110 0->126 1 1->126 2 2->126 3 3->126 4 4->126 5 5->126 6 6->126 7 7->126 8 8->126 9 9->126 10 10->126 11 11->126 12 12->126 13 13->126 14 14->126 15 15->126 16 16->126 17 17->126 18 127 18->127 19 19->127 20 20->127 21 21->127 22 22->127 23 23->127 24 24->127 25 25->127 26 26->127 27 27->127 28 28->127 29 29->127 30 30->127 31 31->127 32 32->126 33 33->126 34 34->126 35 35->126 36 36->126 37 37->126 38 38->126 39 39->126 40 40->126 41 41->126 42 42->126 43 43->126 44 44->126 45 45->126 46 46->126 47 47->126 48 48->126 49 49->126 50 50->126 51 51->126 52 52->126 53 53->126 54 54->126 55 55->126 56 56->126 57 57->126 58 58->126 59 59->126 60 60->126 61 61->126 62 62->126 63 63->126 64 64->126 65 65->126 66 66->126 67 67->126 68 68->126 69 69->126 70 70->126 71 71->126 72 72->126 73 73->126 74 74->126 75 75->126 76 76->126 77 77->126 78 78->126 79 79->126 80 80->127 81 81->127 82 82->127 83 83->127 84 84->127 85 85->127 86 86->127 87 87->127 88 88->127 89 89->127 90 90->127 91 91->127 92 92->127 93 93->127 94 94->126 95 95->126 96 96->126 97 97->126 98 98->126 99 99->126 100 100->126 101 101->126 102 102->126 103 103->126 104 104->126 105 105->126 106 106->126 107 107->126 108 108->126 109 109->126 110 110->126 111 111->126 112 112->126 113 113->126 114 114->126 115 115->126 116 116->126 117 117->126 118 118->126 119 119->126 120 120->126 121 121->126 122 122->126 123 123->126 124 124->126 125 125->126 126->126 127->126

In [ ]: